package com.khaled.protclass.server.bean;

import java.util.ArrayList;

import com.khaled.protclass.model.base.BaseFeature;
import com.khaled.protclass.model.base.IFeature;
import com.khaled.protclass.model.feature.blast.CD;
import com.khaled.protclass.model.feature.blast.PSSM;
import com.khaled.protclass.model.prediction.Classification;
import com.khaled.protclass.server.common.Configuration;
import com.khaled.protclass.server.common.Constants;

public class PredictionApproach
{
	private ArrayList<BaseFeature> features;

	@SuppressWarnings("static-access")
	public PredictionApproach(String approach)
	{
		this.features = new ArrayList<BaseFeature>();

		approach += ",";
		String[] apps = approach.split(",");
		for (String app : apps)
		{
			if (Constants.HTML_FORM_APPROACH_PSSM.equals(app))
			{
				PSSM pssmFeature = new PSSM();
				pssmFeature.getProperties().put(pssmFeature.BLAST_PATH, Configuration.getInstance().get("blast"));
				pssmFeature.getProperties().put(pssmFeature.DB_PATH, Configuration.getInstance().get("blast.db.nr"));

				this.features.add(pssmFeature);
			}
			else if (Constants.HTML_FORM_APPROACH_CD.equals(app))
			{
				CD cdFeature = new CD();
				cdFeature.getProperties().put(cdFeature.BLAST_PATH, Configuration.getInstance().get("blast"));
				cdFeature.getProperties().put(cdFeature.DB_PATH, Configuration.getInstance().get("blast.db.cd"));
				cdFeature.getProperties().put(cdFeature.FEATURE_CD_POSSIBLE_DOMAINS,
						Configuration.getInstance().getWorkingDirectory() + "\\domains.txt");
				
				cdFeature.getProperties().put(cdFeature.FEATURE_CD_CUT_OFF, Configuration.getInstance().get("feature.cd.cutoff"));
				
				cdFeature.getProperties().put(cdFeature.FEATURE_CD_REPRESENTATION, Configuration.getInstance().get("feature.cd.representation"));
				
				cdFeature.init();
				this.features.add(cdFeature);

			}
		}
	}

	public ArrayList<BaseFeature> getFeatures()
	{
		return features;
	}

	public Classification getClassifier() throws Exception
	{
		String modelName = "";
		for (IFeature feature : this.features)
		{
			modelName += feature.getName() + "_";
		}
		modelName = modelName.substring(0, modelName.length() - 1);

		return new Classification(Configuration.getInstance().getWorkingDirectory() + "//" + modelName + ".model");
	}

}
